package com.jm.utils.htmlNode;

import java.util.Vector;

import org.htmlparser.Node;

import com.jm.web.BasePage;




public class NodeList {
	protected Vector<XmlNode> items = null ;
	
	public XmlNode getNode(int index){
		if(items == null)
			return null;
		else
			return items.get(index);
	}
	
	public void addNode(XmlNode node){
		if(items == null)
			items = new Vector<XmlNode>();
		items.add(node);
	}
    
    public int size(){
    	if(items == null)
    		return 0;
    	else
    		return items.size();
    }
    
    public void fromNodeList(org.w3c.dom.NodeList nodes,BasePage page){
    	if(nodes == null)
    		return ;
    	
    	for (int i = 0; i < nodes.getLength(); i++)
		{
			org.w3c.dom.Node childNode = nodes.item(i);
			if(childNode != null){
				XmlNode temp = XmlNode.getInsance(childNode,page);
				if(temp != null)
					this.addNode(temp);
			}
		}
    }
    
    public void fromNodeList(org.htmlparser.util.NodeList nodes,BasePage page){
    	if(nodes == null)
    		return ;
    	
    	for (int i = 0; i < nodes.size(); i++) {
    		Node childNode = nodes.elementAt(i);
    		if(childNode != null){
    			XmlNode temp = XmlNode.getInsance(childNode,page);
				if(temp != null)
					this.addNode(temp);
    		}
		}
    }
}
